<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/jquery.js"></script>
</head>

<body>
    <input type="text" placeholder="请输入用户名"><br>
    <input type="text" placeholder="请输入密码"><br>
    <button>登录</button>
    <script>
        $('button').on('click', function () {
            const username = $('input').eq(0).val().trim();
            const password = $('input').eq(1).val().trim();
            $.ajax({
                type: 'post',
                url: 'http://localhost:3000/login',
                data: {
                    username,
                    password
                },
                success(res) {
                    if (res.status === 200) {
                        console.log(res);
                        localStorage.setItem('token', res.token);
                        location.href = './index.html'
                    } else {
                        alert(res.msg);
                    }
                }
            })
        })
    </script>
</body>

</html>